Micron Document
Livres et Wikis | Archives | Info


Object-oriented programming
part 11/26 Β· 94.0 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Message passing is when the method name and its inputs are sent like a message to the object for it to act on.

Polymorphism

Polymorphism refers to subtyping or subtype polymorphism, where a function can work with a specific interface and thus manipulate entities of different classes in a uniform manner.cite-ref-50[50]

For example, imagine a program has two shapes: a circle and a square. Both come from a common class called "Shape." Each shape has its own way of drawing itself. With subtype polymorphism, the program doesn't need to know the type of each shape, and can simply call the "Draw" method for each shape. The programming language runtime will ensure the correct version of the "Draw" method runs for each shape. Because the details of each shape are handled inside their own classes, this makes the code simpler and more organized, enabling strong separation of concerns.

Open recursion

An object's methods can access the object's data. Many programming languages use a special word, like this or self, to refer to the current object. In languages that support open recursion, a method in an object can call other methods in the same object, including itself, using this special word. This allows a method in one class to call another method defined later in a subclass, a feature known as late binding.

Design patterns

Design patterns are common solutions to problems in software design. Some design patterns are especially useful for OOP, and design patterns are typically introduced in an OOP context.

Object patterns

The following are notable software design patterns for OOP objects.cite-ref-r-c-martin-51-0[51]

β€’ Function object: Class with one main method that acts like an anonymous function (in C++, the function operator, operator())
β€’ Immutable object: does not change state after creation
β€’ First-class object: can be used without restriction
β€’ Container object: contains other objects
β€’ Factory object: creates other objects

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────